/**
 * Created by zhaizy on 2015/4/8.
 */


angular.module("invalidDirective",["utilsService"])

    //zzbUtils要在此处注入，否则不能识别
    .directive('platform', function(utils) {
        return {
            require: 'ngModel',
            link: function($scope, $elm, $attrs, $ctrl) {
                $ctrl.$parsers.unshift(function(viewValue) {
                    console.log("@@##viewValue:"+viewValue+" "+ utils);
                    if (utils.invalidPlatform(viewValue)) {
                        // it is valid
                        $ctrl.$setValidity('platform', true);
                        return viewValue;
                    } else {
                        // it is invalid, return undefined (no model update)
                        $ctrl.$setValidity('platform', false);
                        return viewValue;
                    }
                });
            }
        };
    });